package by.msokoloff.javaweb2015.services.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.metamodel.SingularAttribute;

import org.springframework.stereotype.Service;

import by.msokoloff.javaweb2015.dataaccess.RegistrationDao;
import by.msokoloff.javaweb2015.datamodel.Registration;
import by.msokoloff.javaweb2015.services.RegistrationService;

@Service
public class RegistrationServiceImpl implements RegistrationService {

	@Inject
	private RegistrationDao dao;

	@Override
	public Registration get(Integer id) {
		return dao.getById(id);
	}

	@Override
	public List<Registration> getAll() {
		return dao.getAll();
	}

	@Override
	public void createOrUpdate(Registration registration) {
		if (registration.getId() == null) {
			dao.create(registration);
		} else {
			dao.update(registration);
		}
	}

	@Override
	public void delete(Registration registration) {
		dao.delete(registration.getId());
	}

	@Override
	public void deleteAll() {
		dao.deleteAll();
	}

	@Override
	public long getCount() {
		return dao.getCount();
	}

	@Override
	public List<Registration> getAll(SingularAttribute<Registration, ?> sortParam, boolean ascending, int first, int count) {
		return dao.getAll(sortParam, ascending, first, count);
	}

}
